#include "main_system.h"

const wchar_t *title_user_add= L"用户注册菜单";
const wchar_t *option_user_add[] ={L"继续注册",L"查看注册信息",L"确认注册",L"取消"};
int Sys_user_add(U_list *list,FlightSystem Flight_sys)
{   int flag = 0;
    char temp_passwd[32];
    U_data data;
    strcpy(data.name,"NULL");

    strcpy(data.passwd,"NULL");
    
    while (flag!=3)
    {
    flag = display_menu(title_user_add, option_user_add, 4);
    switch (flag)
    {
    case 1:
        system("clear");
        printf("请输入注册姓名\n\r");
        scanf("%s",data.name);
        printf("请输入密码\n\r");
        scanf("%s",temp_passwd);
        printf("确认密码\n\r");
        scanf("%s",data.passwd);
        break;
    case 2:
        printf("暂存信息:\n姓名：%s\t密码：%s\r\n\n回车以继续",data.name,data.passwd);
        getchar();
        getchar();
        break;
    case 3:

        break;
    default:
        return 0;
        break;
    }
    }
     //   printf("%s ———— %s ,%d\n\r",temp_passwd,data.passwd,0==strcmp(temp_passwd,data.passwd));
       system("clear");
        if(0==strcmp(temp_passwd,data.passwd))
        {   
            data.grade=2;
            data.value=0;
            memset(data.ticket, 0, sizeof(data.ticket));
            
            S_List_insert(Flight_sys.REGULAR_USER,data,1);
            S_List_File_print(Flight_sys.REGULAR_USER,REGULAR_FILE);
            printf("注册成功。\n\r");
            return 0;
        }
            printf("输入的两次密码不同。\n\r");
    return 1;
}

int Sys_user_updata_passwd(U_list *list,FlightSystem Flight_sys)
{   
    U_data user_data = Sys_log_in(list);
   // printf("name:%s,grade:%d",user_data.name,user_data.grade);
    char new_passwd[32];
    char temp_passwd[32];
    printf("请输入新密码\n\r");
    scanf("%s",new_passwd);
    system("clear");
    printf("请再次确认密码\n\r");
    scanf("%s",temp_passwd);
    system("clear");
    
    if(0==strcmp(temp_passwd,new_passwd))
    {
    if(NULL!= S_List_find_name(Flight_sys.ADMIN_USER,user_data.name))
    {
    printf("管理员用户\r\n");
    S_list_up_data_passwd(Flight_sys.ADMIN_USER,S_List_find_name(Flight_sys.ADMIN_USER,user_data.name),temp_passwd);
    S_List_File_print(Flight_sys.ADMIN_USER,ADMIN_FILE);
    printf("管理员:%s 修改密码成功！\r\n",user_data.name);
    }


    if(NULL!= S_List_find_name(Flight_sys.REGULAR_USER,user_data.name))
    {
    printf("普通用户\r\n");
    S_list_up_data_passwd(Flight_sys.REGULAR_USER,S_List_find_name(Flight_sys.REGULAR_USER,user_data.name),temp_passwd);
    S_List_File_print(Flight_sys.REGULAR_USER,REGULAR_FILE);
    printf("普通用户:%s 修改密码成功！\r\n",user_data.name);
    }

    if(NULL!= S_List_find_name(Flight_sys.SILVER_USER,user_data.name))
    {
        
    printf("银卡会员\r\n");
    S_list_up_data_passwd(Flight_sys.SILVER_USER,S_List_find_name(Flight_sys.SILVER_USER,user_data.name),temp_passwd);
    S_List_File_print(Flight_sys.SILVER_USER,SILVER_FILE);
    printf("银卡会员:%s 修改密码成功！\r\n",user_data.name);
    }
    if(NULL!= S_List_find_name(Flight_sys.GOLD_USER,user_data.name))
    {

    printf("金卡会员\r\n");
    S_list_up_data_passwd(Flight_sys.GOLD_USER,S_List_find_name(Flight_sys.GOLD_USER,user_data.name),temp_passwd);
    S_List_File_print(Flight_sys.GOLD_USER,GOLD_FILE);
    printf("金卡会员:%s 修改密码成功！\r\n",user_data.name);
    }
    if(NULL!= S_List_find_name(Flight_sys.PLATINUM_USER,user_data.name))
    {

    printf("白金会员\r\n");
    S_list_up_data_passwd(Flight_sys.PLATINUM_USER,S_List_find_name(Flight_sys.PLATINUM_USER,user_data.name),temp_passwd);
    S_List_File_print(Flight_sys.PLATINUM_USER,PLATINUM_FILE);
    printf("白金会员:%s 修改密码成功！\r\n",user_data.name);
    }

     printf("\n新密码:%s\n\n回车以清除记录并退出\n",temp_passwd);
     getchar();
     getchar();
     system("clear");
     return 0;
    }
    printf("两次密码不匹配\n");
    return 1;
    

}
